package com.isoftstone.service.Impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.isoftstone.dao.LoginDao;
import com.isoftstone.entity.Menu;
import com.isoftstone.entity.Role;
import com.isoftstone.entity.Users;
import com.isoftstone.service.LoginService;




@Service("LoginService")
public class LoginServiceImpl implements LoginService {
	
	@Autowired
	private LoginDao loginDao;
	

	@Override
	public Users getUsersBynameAndPass(String userName, String password) {
		// TODO Auto-generated method stub
		
		Users user = loginDao.getUsersBynameAndPass(userName, password);
		if(user!=null && !"".equals(user.getUser_id())){
			Role role = loginDao.getRoleByUserId(user.getUser_id());
			
			List<Menu> menuList=new ArrayList<Menu>();
			menuList= loginDao.getParentMenuList(role.getRole_id());
			for (Menu menu:menuList){
				List<Menu> childrenMenuList=new ArrayList<Menu>();
				childrenMenuList =loginDao.getChildrenMenuListByParentAndRole(menu.getMenuId(),role.getRole_id());
				menu.setChildrenMenuList(childrenMenuList);
				
			}
			role.setMenuList(menuList);
			user.setRole(role);
			
		}
		return user;
	}
	
}
